package ${controllerPackage}<#--.${sign}-->;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import com.hdac.fms.sys.common.base.BaseResult;
import com.hdac.fms.sys.common.constant.CommonResultConstant;
import com.hdac.fms.sys.common.exception.CommonException;
import ${servicePackage}.${modelNameUpperCamel}Service;
import ${modelPackage}.${modelNameUpperCamel};
import org.springframework.util.StringUtils;
import com.hdac.fms.sys.common.vo.PaginationVO;
import com.hdac.fms.sys.common.scan.log.annotation.ControllerAdapter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * ${modelNameLowerCamel}控制器
 * Created by ${author} on ${date}.
 */
@RestController
@RequestMapping("/hoze/${modelNameLowerCamel}/")
@Api(description="开发中", tags="开发中")
@ControllerAdapter
public class ${modelNameUpperCamel}Controller {

    @Autowired
    ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @ApiOperation(value="分页查询")
    @RequestMapping(value="findByPage", method=RequestMethod.POST)
    public BaseResult findByPage(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}, Integer pageNum, Integer pageSize) {
        PaginationVO<${modelNameUpperCamel}> pageVO = ${modelNameLowerCamel}Service.findPageByModel(${modelNameLowerCamel}, pageNum, pageSize);
        return new BaseResult(CommonResultConstant.SUCCESS, pageVO);
    }

    @ApiOperation(value="保存")
    @ApiImplicitParam(name="${modelNameLowerCamel}", value="实体", paramType="body", required=true, dataType="${modelNameUpperCamel}")
    @RequestMapping(value="insert", method=RequestMethod.POST)
    public BaseResult insert(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}, HttpServletRequest request)  {
        int num = ${modelNameLowerCamel}Service.insertSelective(${modelNameLowerCamel});
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="详情")
    @ApiImplicitParam(name="${primaryKeyName}", value="主键", paramType="query", required=true, dataType="${primaryKeyType}")
    @RequestMapping(value="getById", method=RequestMethod.GET)
    public BaseResult getById(${primaryKeyType} ${primaryKeyName}, HttpServletRequest request) throws CommonException {
        if(StringUtils.isEmpty(${primaryKeyName})){
            throw new CommonException("请选择要编辑的项");
        }
        ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.getById(${primaryKeyName});
        return new BaseResult(CommonResultConstant.SUCCESS, ${modelNameLowerCamel});
    }

    @ApiOperation(value="修改")
    @ApiImplicitParam(name="${modelNameLowerCamel}", value="实体", paramType="body", required=true, dataType="${modelNameUpperCamel}")
    @RequestMapping(value="update", method=RequestMethod.POST)
    public BaseResult update(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}, HttpServletRequest request)  {
        int num = ${modelNameLowerCamel}Service.updateByIdSelective(${modelNameLowerCamel});
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="根据主键删除")
    @ApiImplicitParam(name="${primaryKeyName}", value="主键", paramType="query", required=true, dataType="${primaryKeyType}")
    @RequestMapping(value="delete", method=RequestMethod.GET)
    public BaseResult delete(${primaryKeyType} ${primaryKeyName}, HttpServletRequest request) throws CommonException {
        if(StringUtils.isEmpty(${primaryKeyName})){
            throw new CommonException("请选择要删除的项");
        }
        int num = ${modelNameLowerCamel}Service.deleteById(${primaryKeyName});
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }
}
